package com.fintecher.utils;

import com.fintecher.pojo.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017/2/12.
 */
public class SessionUtils {

    public static final String LOGIN_USER = "loginUser";

    public static void setUser(User user, HttpSession session) {
        session.setAttribute(LOGIN_USER, user);
    }


    public static User getUser(HttpSession session) {
        return (User) session.getAttribute(LOGIN_USER);
    }

    public static User getUser() {
        return (User) getsession().getAttribute(LOGIN_USER);
    }

    public static HttpSession getsession() {
        return getRequest().getSession();
    }

    public static HttpServletRequest getRequest() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

        HttpServletRequest request = requestAttributes.getRequest();

        return request;
    }
}
